import Ele from './Ele'
import Okay from '../Okay'
export default class CompEle extends Ele{
    constructor(tagName, subject, ele, conf = null) {
        super(subject, ele)
        this.tagName = tagName
        this.inst = ele.getAttribute('inst') || tagName
        let config = null
        if(conf == null) {
            if (this.subject.comps.has(tagName)) {
                config = this.subject.comps.get(tagName)
            } else if (Okay.components.has(tagName)) {
                config = Okay.components.get(tagName)
            } else {
                throw '未定义组件：' + tagName
            }
        }else {
            config = conf
        }
        ele.innerHTML = !config.template?'':config.template instanceof Element
            ?config.template.innerHTML
            :config.template.startsWith('#')
                ?document.getElementById(config.template).innerHTML
                :config.template
        this.ele = ele
        this.okays = new Array()
        let data = config.data?config.data():{}
        let oconfig = {
            ele: this.ele,
            data: data,
            filters: config.filters || {},
            components: config.components || {},
            routes: config.routes || [],
            builder: config.builder,
            parent: this,
            parent_field: this.subject.parent_field,
            action_classes: config.action_classes || {},
            aop:config.aop || {},
            on_create: config.on_create || undefined,
            on_resume: config.on_resume || undefined,
            on_pause: config.on_pause || undefined,
            on_stop: config.on_stop || undefined,
            on_destroy: config.on_destroy || undefined,
            on_restart: config.on_restart || undefined
        }
        new Okay(oconfig)
    }
}